//
//  BaseViewController.swift
//  JiaXiaoTong
//
//  Created by leo on 2018/2/5.
//  Copyright © 2018年 IT. All rights reserved.
//

import UIKit

class BaseViewController: UIViewController {
    var setTitle : String?
    var noDataView : NoChartDataView?
    

    override func viewDidLoad() {
        super.viewDidLoad()
        self.automaticallyAdjustsScrollViewInsets = true
        self.view.backgroundColor = UIColor_Hex.withHex(hexString: "#f5f5f5")
        self.setNaviPopToBackItem()
        let frame =   CGRect(x: 0, y: 64, width:TPWidth  , height: TPHeight)
        let noDataView  = NoChartDataView.init(frame:frame, title:getLanguageManageKey(key:"No data for the time being"))
        self.noDataView = noDataView
        noDataView?.backgroundColor = UIColor.white
        noDataView?.isHidden = true
        self.view.addSubview(noDataView!)
       
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func setNaviPopToBackItem(){
        
        let vcNum = self.navigationController?.viewControllers.count
        if vcNum != 1 {
           
            let   button :UIButton = UIButton.init(imge: "center_ico_back", width: 100, height: 40)
            button.addTarget(self, action: Selector(("popToBack")), for: .touchUpInside)
            let leftItem = UIBarButtonItem.init(customView: button)
            self.navigationItem.leftBarButtonItem = leftItem
        }
        
    }
    func popToBack(){
        if (self.navigationController != nil) {
            
            if (self.navigationController!.viewControllers.count > 1 ){
                
                self.navigationController?.popViewController(animated: true)
            }else{
                
                self.navigationController?.dismiss(animated: true, completion: {
                    
                })
            }
            
        }
        
    }
    deinit {
     NotificationCenter.default.removeObserver(self)
    }
   
}

//- (void)popToBack{
//
//    if (self.navigationController) {
//        if ([self.navigationController viewControllers].count > 1) {
//            [self.navigationController popViewControllerAnimated:YES];
//        } else {
//            [self.navigationController dismissViewControllerAnimated:YES completion:nil];
//        }
//    } else {
//        [self dismissViewControllerAnimated:YES completion:nil];
//    }
//}
//
//-(void)dealloc
//    {
//        [[NSNotificationCenter defaultCenter] removeObserver:self];
//}


extension BaseViewController {
    
    
    
//    self.automaticallyAdjustsScrollViewInsets  = YES;
//
//    self.view.backgroundColor = [UIColor colorWithHexString:@"#f5f5f5"];
//
//    [self setNaviPopToBackItem];
//
//
//    NoChartDataView *noDataView = [[NoChartDataView alloc] initWithFrame:CGRectMake(0, 64, TPWidth, TPHeight - 49 - 64) text:getLanguageManageKey(@"No data for the time being")];
//    self.noDataView = noDataView;
//    noDataView.backgroundColor = [UIColor whiteColor];
//    noDataView.hidden = YES;
//    [self.view addSubview:noDataView];
//
    
    
    
}



